<!DOCTYPE HTML>
<html>
    <head>
        <title>后台管理系统</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="/layui/css/layui.css" type="text/css">
        <link rel="stylesheet" href="/static/css/back.css" type="text/css">

        <script src="/static/js/jquery-3.5.0.min.js"></script>
        <script src="/layui/layui.all.js"></script> 
        <!--<script src="/static/js/base64.js"></script>-->
        <script>

            var layer = layui.layer;
            //缓存
            //获取缓存
            function cache_get(name) {
                if (name) {
                    return layui.data('cache', name);
                } else {
                    return layui.data('cache');
                }
            }
            //设置缓存
            function cache_set(name, value) {
                layui.data('cache', {key: name, value: value});
            }
            //删除缓存
            function cache_del(name) {
                if (name) {
                    layui.data('cache', {key: name, remove: true});
                } else {
                    layui.data('cache', null);
                }
            }
            var login = cache_get('login');
            if (login) {
                var user = cache_get('user');
            } else {
                var user = layui.sessionData('cache', 'user');
            }
            if (!user) {
                window.location.href = 'login.html';
            }
            var upfile = '/admin/common/up_img';

            //ajax请求数据callback回调方法            
            function re_ajax(url, data, callback, method = 'GET') {
                $.ajax({
                    type: method,
                    data: data,
                    dataType: 'JSON',
                    url: url,
                    beforeSend: function (request) {
                        request.setRequestHeader("Authorization", user.token);
                    },
                    success: function (d) {
                        //没成功的都要提示信息
                        if (d.msg != 'SUCCESS') {
                            layer.msg(d.msg, {time: 1000});
                        }
                        //用户失效跳登录页面
                        if (d.code == 300) {
//                            window.location.href = 'login.html';
                        }
                        if (callback) {
                            callback(d);
                        }
                    }
                });
            }

            //设置状态颜色
            function get_status(status) {
                if (status == 1) {
                    return '<font color="#228B22">启用</font>';
                } else if (status == 0) {
                    return '<font color="#FF6347">禁用</font>';
                } else if (status == -1) {
                    return '<font color="#C0C0C0">删除</font>';
                }
            }
            //处理表单数据
            function setFormData(data) {
                var d = '';
                for (k in data) {
                    var v = data[k];
                    d += '&' + k + '=' + v;
                }
                return d;
            }
            //加密方法
            function str_encode(str) {
                var string = Base64.encode(str);
                if (string.length >= 4) {
                    string = string.substr(2, 2) + string;
                }
                return string;
            }
            //解密方法
            function str_decode(str) {
                try {
                    if (str.length >= 6) {
                        str = str.substr(2);
                    }
                    return Base64.decode(str);
                } catch (e) {
                    console.log(e);
                }
                return str;
            }
            //三级联动
            var select_tree = function (url, select_data) {
                var select_tree_data = [];
                re_ajax(url, '', function (d) {
                    if (d.code == 200) {
                        select_tree_data = d.data;
                        set_select_tree(0, 0);
                    }
                });
                function set_select_tree(pid, select_tree_num) {
                    var data = select_tree_data[pid];
                    var options = '<option value="">请选择</option>';
                    for (var k in data) {
                        var selected = select_data && select_data[select_tree_num] == data[k].id ? 'selected' : '';
                        options += '<option value=' + data[k].id + ' ' + selected + '>' + data[k].name + '</option> ';
                    }
                    $('#select-tree' + select_tree_num).html(options);
                    if (select_data && select_data[select_tree_num]) {
                        set_select_tree(select_data[select_tree_num], ++select_tree_num);
                    }
                    form.render('select');
                }
                form.on('select(select-tree)', function (data) {
                    var select_tree_num = $(data.elem).data('item');
                    select_tree_num++;
                    set_select_tree(data.value, select_tree_num);
                });
            };

            //搜索输入选择
            var sou_select = function (elem, url, callback = null) {
                var html = '<div class="layui-unselect layui-form-select layui-form-selected sou-select-box">';
                html += '</div>';
                $('body').on('keyup', elem, function () {
                    var obj = $(this);
                    obj.after(html);
                    var key = $(this).val();
                    $('.sou-select-box').html('');
                    re_ajax(url, 'key=' + key, function (d) {
//                        if (d.data.length > 0) {
                        var dl = '<dl class="layui-anim layui-anim-upbit "><dd data-value="" class="layui-select-tips">请选择</dd>';
                        for (var k in d.data) {
                            dl += '<dd data-value="' + d.data[k].id + '">' + d.data[k].name + '</dd>';
                        }
                        dl += '</dl>';
                        $('.sou-select-box').html(dl);
                        $('.sou-select-box dl').show();

                        $('.sou-select-box dl dd').click(function () {
//                                alert(123);
                            var id = $(this).data('value');
                            var name = $(this).text();
                            obj.attr('data-souid', id);
                            obj.val(name);
                            $('.sou-select-box').remove();
                            if (callback) {
                                callback(obj, id, name);
                            }
                        });
//                        }
                    });

                });

//                $(elem).blur(function(){
//                    $('.sou-select-box dl').hide();
//                });
            }

        </script>    
    </head>
    <body>        
        <!--头部-->
        <header>
            <div class="logo" style="width: 1rem;"><i class="layui-icon layui-icon-shrink-right"></i></div>
            <!--<div class="search"><input type="text" name="search" value="" placeholder="搜索课程"><i class="layui-icon layui-icon-search"></i></div>-->
            <h1 class="ff-title">后台管理系统</h1>
            <div class="userinfo">
                <p class="ff-hd-user"><img src="/static/image/captcha.png"><a></a></p>
                <ul class="ff-nav ff-hd-ul">
                    <!--<li><a>消息</a></li>-->
                    <!--<li id="upinfo">修改个人信息</li>-->
                    <!--<li id="clear-cache">清除缓存</li>-->
                    <li  id="logout">退出</li>
                </ul>
            </div>
        </header>
        <!--内容-->
        <main>
            <div class="ff-body-title"><a href="/back">首页/</a><span class="crumb"></span>
                <span class="ff-body-pageset">
                    <a class="reload" title="刷新"><i class="layui-icon layui-icon-refresh-3"></i>  </a>
                    <a class="goback" title="返回"><i class="layui-icon layui-icon-return"></i></a>
                </span>
            </div>
            <div class="ff-body">
                <!--调用模板-->

                <!--模板结束-->
            </div>
        </main>
        <!--左侧菜单-->
        <footer>
            <ul class="ff-nav">
                <li class="logo"><h3><i class="layui-icon layui-icon-shrink-right"></i><a href="back">后台管理系统</a></h3></li>
                <!--<li class="home"><h3><i class="layui-icon layui-icon-home"></i><a href="back">首页</a></h3></li>-->
            </ul>
        </footer>
        <!--提示声音-->
        <!--<audio id="playbell" src="/static/bell.mp3"></audio>-->

        <!--列表有删除按钮-->
        <script type="text/html" id="action">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>            
        </script>
        <!--列表无删除按钮-->
        <script type="text/html" id="actiond">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
        </script>
        <!--添加按钮-->
        <script type="text/html" id="action-add">
            <a class="layui-btn layui-btn-sm" lay-event="add">添加</a>
            <a class="layui-btn layui-btn-sm layui-btn-danger" id="delrows" style="display: none;" lay-event="delete">删除</a>
        </script>
        <!--导出数据-->
        <script type="text/html" id="action-daochu">
            <a class="layui-btn layui-btn-sm" lay-event="daochu">导出数据</a><font color="red">(搜索可以筛选条件)</font>
        </script>

        <!--首页数据图-->
        <script src="/static/js/echarts.min.js"></script> 
        <!--<script src="/static/js/wangEditor.min.js"></script>-->
        <script src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script>
        <!--<script src="https://webapi.amap.com/maps?v=2.0&key=6df1929b6d721485176ddd1068048fe4"></script>-->

        <!--业务逻辑处理-->        
        <script src="/static/js/ac.js"></script> 

    </body>
</html>
